package com.xkh.common.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiKey;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author: xkh
 * @Date: 2019/9/14
 * @Version 1.0
 * 通过@Configuration注解，让Spring来加载该类配置
 * 再通过@EnableSwagger2注解来启用Swagger2
 */
@Configuration
@EnableSwagger2
public class Swagger2 {

    @Bean("工具模块")
    public Docket createRestApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("工具模块")
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.xkh.common.controller"))
                .build()
                .apiInfo(new ApiInfoBuilder().title("工具模块").build())
                .securitySchemes(securitySchemes());
    }

    private List<ApiKey> securitySchemes() {
        List<ApiKey> apiKeyList = new ArrayList<>();
        apiKeyList.add(new ApiKey("token", "token", "header"));
        return apiKeyList;
    }

}
